﻿import QtQuick 2.15
import QtQuick.Controls 2.15

/*
  超短加工界面
*/

Item {
    id:backGround
    width: screenWidth
    height: 1600

    Rectangle{
        anchors.fill: backGround
        color: "#00bfff"
        border.width: 5
        border.color: "#F0F8FF"
    }

    onVisibleChanged: {
        if(visible === true)
        {
            Cpp_Connect.pageNumber = 3
        }
    }

    // 旋钮部分模式
    property int currentMode: Cpp_Connect.knobMode === "1" ? 1 : Cpp_Connect.knobMode === "2" ? 2 : 0
    // 左锯 当前模式
    property bool leftSaw45Mode: Cpp_Connect.leftSawAngle
    // 右锯 当前模式
    property bool rightSaw45Mode: Cpp_Connect.rightSawAngle



    Rectangle{      // 顶部旋钮区域
        anchors.top: backGround.top
        anchors.horizontalCenter: backGround.horizontalCenter
        color: "#00bfff"
        border.width: 5
        border.color: "#F0F8FF"
        width: backGround.width
        height: 420

        Rectangle{      // 左机头
            id:top_leftMechine
            anchors.left: parent.left
            anchors.top: parent.top
            width: 250
            height: parent.height
            color: "lightgray"
            border.width: 5
            border.color: "#F0F8FF"
            visible: !Cpp_Connect.Angle45_Mode

            Rectangle{
                anchors.top: parent.top
                anchors.topMargin: 33
                anchors.left: parent.left
                anchors.leftMargin: 20
                width: 30
                height: 30
                radius: 30
                border.width: 1
                color: Cpp_Connect.leftSawQW ? "red" : "white"
            }

            Rectangle{
                anchors.top: parent.top
                anchors.topMargin: 33
                anchors.right: parent.right
                anchors.rightMargin: 20
                width: 30
                height: 30
                radius: 30
                border.width: 1
                color: Cpp_Connect.leftSawHW ? "red" : "white"
            }

            Rectangle{      // 子标题
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                anchors.topMargin: 20
                width: 150
                height: 60
                color: "transparent"

                Text{
                    anchors.centerIn: parent
                    font.pixelSize: 40
                    text:qsTr("左机头")
                    font.bold: true
                }
            }

            Rectangle{
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                anchors.topMargin: 140
                width: parent.width - 20
                height: 100
                radius: 10
                color: leftSaw45Mode ? "#006cee" : "#ff3606"

                Text{
                    anchors.centerIn: parent
                    font.pixelSize: 40
                    font.bold: true
                    text:qsTr("左45度")
                }

                MouseArea{
                    anchors.fill: parent

                    onPressed: {
                        parent.forceActiveFocus()
                        Cpp_Connect.write_modbus_rtu_Coils("13","1");
                    }

                    onReleased: {
                        Cpp_Connect.write_modbus_rtu_Coils("13","0");
                    }

                }

            }

            Rectangle{
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                anchors.topMargin: 270
                width: parent.width - 20
                height: 100
                radius: 10
                color: leftSaw45Mode ? "#ff3606" : "#006cee"

                Text{
                    anchors.centerIn: parent
                    font.pixelSize: 40
                    font.bold: true
                    text:qsTr("左90度")
                }

                MouseArea{
                    anchors.fill: parent

                    onPressed: {
                        parent.forceActiveFocus()
                        Cpp_Connect.write_modbus_rtu_Coils("15","1");
                    }

                    onReleased: {
                        // parent.forceActiveFocus()
                        Cpp_Connect.write_modbus_rtu_Coils("15","0");
                    }
                }
            }
        }

/////////////////////////////////////////////////////////

        Rectangle{      // 中间切换旋钮
            anchors.top: parent.top
            anchors.horizontalCenter: parent.horizontalCenter
            width: parent.width - top_leftMechine.width - top_rightMechine.width
            height: parent.height
            border.width: 5
            border.color: "#F0F8FF"
            color: "gold"

            Rectangle{
                id: leftSaw
                anchors.left: parent.left
                anchors.top: parent.top
                width: (parent.width ) / 3
                height: 100
                border.width: 5
                border.color: "#f0f8ff"
                color: currentMode === 0 ? "green" : currentMode === 1 ? "green" : "transparent"

                Text{
                    anchors.centerIn: parent
                    font.pixelSize: 30
                    font.bold: true
                    text:qsTr("左锯")
                }

                MouseArea{
                    anchors.fill: parent

                    onClicked: {
                        Cpp_Connect.write_modbus_rtu_Hold("229","1")
                    }
                }

            }
            Rectangle{
                id: bothSaws
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                width: ((parent.width ) / 3 + 3)
                height: 100
                border.width: 5
                border.color: "#f0f8ff"
                color: currentMode === 0 ? "blue" :"transparent"

                Text{
                    anchors.centerIn: parent
                    font.pixelSize: 30
                    font.bold: true
                    text:qsTr("联动")
                }

                MouseArea{
                    anchors.fill: parent

                    onClicked: {
                        Cpp_Connect.write_modbus_rtu_Hold("229","0")
                    }
                }

            }
            Rectangle{
                id: rightSaw
                anchors.right: parent.right
                anchors.top: parent.top
                width: (parent.width ) / 3
                height: 100
                border.width: 5
                border.color: "#f0f8ff"
                color: currentMode === 0 ? "green" : currentMode === 2 ? "green" : "transparent"

                Text{
                    anchors.centerIn: parent
                    font.pixelSize: 30
                    font.bold: true
                    text:qsTr("右锯")
                }

                MouseArea{
                    anchors.fill: parent

                    onClicked: {
                        Cpp_Connect.write_modbus_rtu_Hold("229","2")
                    }
                }

            }


            Rectangle{
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                anchors.topMargin: 120
                width: 290
                height: 290
                color: "transparent"

                Image {
                    id: knob_Process
                    anchors.fill: parent
                    source: "qrc:/Image/knob.png"
                    rotation: currentMode === 0 ? 90 : currentMode === 1 ? 45 : 135
                }

                MouseArea{
                    anchors.fill: parent

                    onClicked: {
                        parent.forceActiveFocus()
                        if(currentMode === 0)
                        {
                            Cpp_Connect.write_modbus_rtu_Hold("229","1")
                        }
                        else if(currentMode === 1)
                        {
                            Cpp_Connect.write_modbus_rtu_Hold("229","2")
                        }
                        else if(currentMode === 2)
                        {
                            Cpp_Connect.write_modbus_rtu_Hold("229","0")
                        }
                    }
                }
            }
        }

/////////////////////////////////////////////////////////

        Rectangle{      // 右机头
            id:top_rightMechine
            anchors.right: parent.right
            anchors.top: parent.top
            width: 250
            height: parent.height
            color: "lightgray"
            border.width: 5
            border.color: "#F0F8FF"
            visible: !Cpp_Connect.Angle45_Mode

            Rectangle{
                anchors.top: parent.top
                anchors.topMargin: 33
                anchors.left: parent.left
                anchors.leftMargin: 20
                width: 30
                height: 30
                radius: 30
                border.width: 1
                color: Cpp_Connect.rightSawQW ? "red" : "white"
            }
            Rectangle{
                anchors.top: parent.top
                anchors.topMargin: 33
                anchors.right: parent.right
                anchors.rightMargin: 20
                width: 30
                height: 30
                radius: 30
                border.width: 1
                color: Cpp_Connect.rightSawHW ? "red" : "white"
            }

            Rectangle{      // 子标题
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                anchors.topMargin: 20
                width: 150
                height: 60
                color: "transparent"

                Text{
                    anchors.centerIn: parent
                    font.pixelSize: 40
                    text:qsTr("右机头")
                    font.bold: true
                }
            }

            Rectangle{
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                anchors.topMargin: 140
                width: parent.width - 20
                height: 100
                radius: 10
                color: rightSaw45Mode ? "#006cee" :  "#ff3606"

                Text{
                    anchors.centerIn: parent
                    font.pixelSize: 40
                    font.bold: true
                    text:qsTr("右45度")
                }

                MouseArea{
                    anchors.fill: parent

                    onPressed: {
                        parent.forceActiveFocus()
                        Cpp_Connect.write_modbus_rtu_Coils("14","1");
                    }

                    onReleased: {
                        // parent.forceActiveFocus()
                        Cpp_Connect.write_modbus_rtu_Coils("14","0");
                    }
                }


            }

            Rectangle{
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.top: parent.top
                anchors.topMargin: 270
                width: parent.width - 20
                height: 100
                radius: 10
                color: rightSaw45Mode ?  "#ff3606" : "#006cee"

                Text{
                    anchors.centerIn: parent
                    font.pixelSize: 40
                    font.bold: true
                    text:qsTr("右90度")
                }

                MouseArea{
                    anchors.fill: parent

                    onPressed: {
                        parent.forceActiveFocus()
                        Cpp_Connect.write_modbus_rtu_Coils("16","1");
                    }

                    onReleased: {
                        // parent.forceActiveFocus()
                        Cpp_Connect.write_modbus_rtu_Coils("16","0");
                    }
                }
            }
        }
    }

    ///////////////////////////////////

    Rectangle{      // 复位按钮
        width: 220
        height: 100
        radius: 10
        color: "#006cee"
        border.width: 1
        border.color: "#F0F8FF"
        anchors.top: backGround.top
        anchors.topMargin: 450
        anchors.left: backGround.left
        anchors.leftMargin: 30

        Text{
            anchors.centerIn: parent
            font.pixelSize: 40
            font.bold: true
            text:qsTr("复 位")
        }

        MouseArea{
            anchors.fill: parent

            onPressed: {
                parent.forceActiveFocus()
                parent.color = "#ff3606"
                Cpp_Connect.write_modbus_rtu_Coils("5","1");
            }

            onReleased: {
                parent.color = "#006cee"
                Cpp_Connect.write_modbus_rtu_Coils("5","0");
            }
        }

    }

    ///////////////////////////////////

    Rectangle{
        width: backGround.width
        height: 150
        color: "#00bfff"
        border.width: 5
        border.color: "#F0F8FF"
        anchors.top: backGround.top
        anchors.topMargin: 580
        anchors.horizontalCenter: backGround.horizontalCenter
        visible: !Cpp_Connect.NBWB_Mode

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            font.bold: true
            font.pixelSize: 30
            text: qsTr("料高设定")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:lg_Setting_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.LG_value
            }

            TextInput{      // 料高设定输入
                id:lg_Setting_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false
                // text:lg_Setting_Text.text

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("214",lg_Setting_Input.text)
                    lg_Setting_Text.visible = true
                    lg_Setting_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    lg_Setting_Input.forceActiveFocus()
                    lg_Setting_Input.text = lg_Setting_Text.text
                    lg_Setting_Text.visible = false
                    lg_Setting_Input.visible = true
                    lg_Setting_Input.selectAll()
                }
            }
        }
    }

    Rectangle{
        width: backGround.width
        height: 150
        color: "#00bfff"
        border.width: 5
        border.color: "#F0F8FF"
        anchors.top: backGround.top
        anchors.topMargin: 725
        anchors.horizontalCenter: backGround.horizontalCenter

        Text{
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 30
            font.bold: true
            font.pixelSize: 30
            text:qsTr("超短料长")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:cd_MatterLong_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.ExtraShort_LC
            }

            TextInput{      // 超短料长输入框
                id:cd_MatterLong_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false
                // text:cd_MatterLong_Text.text

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("224",cd_MatterLong_Input.text)
                    cd_MatterLong_Text.visible = true
                    cd_MatterLong_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    cd_MatterLong_Input.forceActiveFocus()
                    cd_MatterLong_Input.text = cd_MatterLong_Text.text
                    cd_MatterLong_Input.visible = true
                    cd_MatterLong_Text.visible = false
                    cd_MatterLong_Input.selectAll()
                }
            }
        }
    }

    Rectangle{
        width: backGround.width
        height: 150
        color: "#00bfff"
        border.width: 5
        border.color: "#F0F8FF"
        anchors.top: backGround.top
        anchors.topMargin: 870
        anchors.horizontalCenter: backGround.horizontalCenter

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            font.bold: true
            font.pixelSize: 30
            text: qsTr("超短补偿")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:locationCompensate_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.ExtraShortCompensate
            }

            TextInput{      // 位置补偿输入
                id:locationCompensate_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false
                // text:locationCompensate_Text.text

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("1380",locationCompensate_Input.text)
                    locationCompensate_Text.visible = true
                    locationCompensate_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    locationCompensate_Input.forceActiveFocus()
                    locationCompensate_Input.text = locationCompensate_Text.text
                    locationCompensate_Text.visible = false
                    locationCompensate_Input.visible = true
                    locationCompensate_Input.selectAll()
                }
            }
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 420
            anchors.verticalCenter: parent.verticalCenter
            font.bold: true
            font.pixelSize: 30
            text: qsTr("回拉距离")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 570
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"

            Text{
                id:pullBack_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                text: Cpp_Connect.HL_Distance
            }

            TextInput{      // 回拉距离输入
                id:pullBack_Input
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                font.italic: true
                maximumLength: 10
                visible: false
                // text:pullBack_Text.text

                onEditingFinished: {
                    Cpp_Connect.write_modbus_rtu_Hold_F("1390",pullBack_Input.text)
                    pullBack_Text.visible = true
                    pullBack_Input.visible = false
                }
            }

            MouseArea{
                anchors.fill: parent

                onClicked: {
                    pullBack_Input.forceActiveFocus()
                    pullBack_Input.text = pullBack_Text.text
                    pullBack_Text.visible = false
                    pullBack_Input.visible = true
                    pullBack_Input.selectAll()
                }
            }
        }
    }

    Rectangle{
        width: backGround.width
        height: 150
        color: "#00bfff"
        border.width: 5
        border.color: "#F0F8FF"
        anchors.top: backGround.top
        anchors.topMargin: 1005
        anchors.horizontalCenter: backGround.horizontalCenter        

        Text{           // 超短料长下限
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 30
            font.pixelSize: 30
            font.bold: true
            text: qsTr( Cpp_Connect.ExtraShort_D_Limit +" mm")
        }

        Text{
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 220
            font.pixelSize: 30
            font.bold: true
            text:qsTr("<   短料料长范围   < ")
        }

        Text{           // 超短料长下限
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: parent.left
            anchors.leftMargin: 600
            font.pixelSize: 30
            font.bold: true
            text: qsTr( Cpp_Connect.ExtraShort_U_Limit +" mm")
        }

    }




    Rectangle{
        width: backGround.width
        height: 150
        color: "#00bfff"
        border.width: 5
        border.color: "#F0F8FF"
        anchors.top: backGround.top
        anchors.topMargin: 1150
        anchors.horizontalCenter: backGround.horizontalCenter

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            font.bold: true
            font.pixelSize: 30
            text: qsTr("当前段数")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"
            color: "black"

            Text{           //  当前段数显示
                id:currentDS_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                visible: true
                color: "aqua"
                text: Cpp_Connect.currentSectiones
            }
        }

        Rectangle{          // 段数清空按钮
            anchors.left: parent.left
            anchors.leftMargin: 420
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            border.width: 1
            border.color: "#F0F8FF"
            color: "#006cee"

            Text{
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                text:qsTr("段数清零")
            }

            MouseArea{
                anchors.fill: parent

                onPressed: {
                    parent.forceActiveFocus()
                    parent.color = "#ff3606"
                    Cpp_Connect.write_modbus_rtu_Coils("75","1");
                }

                onReleased: {
                    parent.color = "#006cee"
                    Cpp_Connect.write_modbus_rtu_Coils("75","0");
                }
            }
        }


    }

    Rectangle{
        width: backGround.width
        height: 150
        color: "#00bfff"
        border.width: 5
        border.color: "#F0F8FF"
        anchors.top: backGround.top
        anchors.topMargin: 1295
        anchors.horizontalCenter: backGround.horizontalCenter

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            font.bold: true
            font.pixelSize: 30
            text: qsTr("当前位置")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 180
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            color: "black"
            border.width: 1
            border.color: "#F0F8FF"

            Text{       // 当前位置显示
                id:currentLocation_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                color: "aqua"
                visible: true
                text: Cpp_Connect.currentLocation
            }
        }

        Text{
            anchors.left: parent.left
            anchors.leftMargin: 440
            anchors.verticalCenter: parent.verticalCenter
            font.bold: true
            font.pixelSize: 30
            text: qsTr("X轴当前位置")
        }

        Rectangle{
            anchors.left: parent.left
            anchors.leftMargin: 630
            anchors.verticalCenter: parent.verticalCenter
            width: 200
            height: 100
            radius: 10
            color: "black"
            border.width: 1
            border.color: "#F0F8FF"

            Text{       // X轴当前位置显示
                id:currentLocationXAxis_Text
                anchors.centerIn: parent
                font.pixelSize: 30
                font.bold: true
                color: "aqua"
                visible: true
                text: Cpp_Connect.xAxisCurrentLocation
            }
        }
    }
}
